﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DBUtility;

namespace DAL
{
    public class AbanINStockDAL
    {
        /// <summary>
        /// GetAbanINStockList
        /// </summary>
        /// <returns></returns>
        public DataSet GetAbanINStockList()
        {
            DataSet ds = new DataSet();
            StringBuilder sql = new StringBuilder();
            bool result = false;
          

            sql.Append("  select ROW_NUMBER()  over(order by a.FBillNo)num,a.FBillNo,a.FEntryID,a.Fdate,a.Fry,c.NAME,  ");
            sql.Append("  a.total, a.leftQty  from  ");
            sql.Append(" 	(  select FBillNo,CONVERT(VARCHAR(10),Fdate,23) Fdate,Fry,FEntryID  ");
            sql.Append(" 	 ,COUNT(0) total,  sum(case flag when 0 then 1 else 0 end) leftQty   ");
            sql.Append(" 	 from t_AbanINStockDetail GROUP BY FBillNo,CONVERT(VARCHAR(10),Fdate,23)  ");
            sql.Append(" 	  ,Fry,FEntryID ");
            sql.Append(" 	  ) a     ");
            sql.Append("  left join t_SEOutStockEntry b on b.FEntryID= a.FEntryID and b.FBillNo=a.FBillNo  ");
            sql.Append("  left join sys_master c on c.ID = a.Fry      ");
            sql.Append("  where b.States = '6'   ");

            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                ds = DbHelperSQL.Query(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return ds;
        }
        /// <summary>
        /// 获取入库条码
        /// </summary>
        /// <param name="PkgsBarCode"></param>
        /// <param name="PlaceBarCode"></param>
        /// <param name="PlaceName"></param>
        /// <returns></returns>
        public bool GetAbanINCode(string PkgsBarCode, string FBillNo, out string PlaceBarCode, out string PlaceName, out string FInterID, out string dc)
        {
            bool result = false;
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            PlaceBarCode = ""; PlaceName = ""; FInterID = ""; dc = "";
          
            commandText.Append(" SELECT  b.Fnumber +'层'+  CAST(C.Floor AS nvarchar) PlaceName,B.PlaceBarCode,FInterID, ");
            commandText.Append("  case SUBSTRING(c.HelperCode,1,1) when 'A' then '定尺'  when '不定尺' then '2' end dc  ");
            commandText.Append("   FROM t_AbanINStockDetail A  ");
            commandText.Append("  left join t_StockPlace  B ON A.PosiID=B.FSPID  ");
            commandText.Append("  left join stk_Package c on c.PkgsBarCode = a.PkgsBarCode ");
            commandText.Append("  WHERE  A.PkgsBarCode='" + PkgsBarCode + "' and   FBillNo ='" + FBillNo + "' ");

            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                ds = DbHelperSQL.Query(commandText.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (ds != null)
            {
              
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    PlaceBarCode = dr["PlaceBarCode"].ToString().Trim(); if (PlaceBarCode != null) { result = true; } else { return false; }
                    PlaceName = dr["PlaceName"].ToString().Trim(); if (PlaceName != null) { result = true; } else { return false; }
                    FInterID = dr["FInterID"].ToString().Trim(); if (FInterID != null) { result = true; } else { return false; }
                    dc = dr["dc"].ToString().Trim(); if (dc != null) { result = true; } else { return false; }
                }
            }
            return result;
        }



        /// <summary>
        /// 报废入库单细表
        /// </summary>
        /// <param name="FBillNo"></param>
        /// <param name="FEntryID"></param>
        /// <returns></returns>
        public DataSet GetAbanINStockDetail(string FBillNo, string FEntryID)
        {
            DataSet ds = new DataSet();
            StringBuilder sql = new StringBuilder();
            bool result = false;

            sql.Append("  select  t.FBillNo,t.FEntryID,t.FInterID,t.PkgsBarCode,a.PlaceBarCode,t.FSku,t.StickLen,t.FQty,b.FItemName,b.AttrValue,t.StockID");
            sql.Append("  ,t.PosiID,a.FName PlaceName ");
            sql.Append("    from t_AbanINStockDetail t ");
            sql.Append("   left join  t_StockPlace a on  a.FSPID = t.PosiID ");
            sql.Append("   left join t_ICItemSku b on b.FSku = t.FSku ");
            sql.Append("  where t.FBillNo ='" + FBillNo + "' and t.FEntryID =  '" + FEntryID + "'  and flag = 0");

          
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                ds = DbHelperSQL.Query(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ds;
        }

        /// <summary>
        /// 获取库位名称
        /// </summary>
        public bool GetPlaceName(string PlaceBarCode, out string PlaceName)
        {
            bool lb_return = false;
            PlaceName = "";

            DataSet dt = new DataSet();
            StringBuilder sql = new StringBuilder();
            sql.Append(" select FNumber from t_StockPlace where PlaceBarCode = '" + PlaceBarCode + "'");
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                dt = DbHelperSQL.Query(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (dt != null)
            {
                foreach (DataRow dr in dt.Tables[0].Rows)
                {
                    PlaceName = dr[0].ToString().Trim();
                }
            }

            if (PlaceName == null || PlaceName == "") { lb_return = false; } else { lb_return = true; }

            return lb_return;
        }


        /// <summary>
        /// 更新明细库位信息
        /// </summary>
        public bool UpdateAbanINStock(string FInterID, string PkgsBarCode, string PlaceBarCode, string dc, string Fry)
        {
            bool lb_return = false;
            string stockID = ""; string PosiID = "";
            string PkgsIsRegularID = "";
            string FinishDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            if (dc == "不定尺")
            {
                PkgsIsRegularID = "2";
            }
            else
            {
                PkgsIsRegularID = "1";
            }

            lb_return = GetStockPosi(PlaceBarCode, out stockID, out PosiID);

            if (lb_return)
            {
                StringBuilder commandText = new StringBuilder();
                commandText.Append(" update t_AbanINStockDetail set ");
                commandText.Append(" PkgsBarCode='" + PkgsBarCode + "'");
                commandText.Append(" ,StockID='" + stockID + "'");
                commandText.Append(" ,PosiID='" + PosiID + "'");
                commandText.Append(" ,flag='1',FinishID='" + Fry + "',FinishDate='" + FinishDate + "'");
                commandText.Append(" ,PkgsIsRegular='" + PkgsIsRegularID + "'");
                commandText.Append(" where FInterID='" + FInterID + "' and flag = 0");

                try
                {
                    DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                    int i = DbHelperSQL.ExecuteSql(commandText.ToString());
                    if (i > 0)
                    { lb_return = true; }
                    else { lb_return = false; }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return lb_return;
        }


        //获取仓库  库位
        public bool GetStockPosi(string PlaceBarCode, out string stockID, out string PosiID)
        {
            bool lb_return = false;
            stockID = ""; PosiID = "";
            DataSet dt = new DataSet();
            StringBuilder sql = new StringBuilder();
            sql.Append(" select FParentID,FSPID from t_StockPlace where PlaceBarCode = '" + PlaceBarCode + "'");
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                dt = DbHelperSQL.Query(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (dt != null)
            {
                lb_return = true;

                foreach (DataRow dr in dt.Tables[0].Rows)
                {
                    stockID = dr[0].ToString().Trim();
                    PosiID = dr[1].ToString().Trim();
                }
            }

            return lb_return;
        }
        //获取层
        public bool GetFloor(string PlaceBarCode, out string Floor)
        {
            bool lb_return = false;
            Floor = "";

            DataSet dt = new DataSet();
            StringBuilder commandText = new StringBuilder();

            commandText.Append(" select MAX(a.Floor) Floor");
            commandText.Append(" from stk_Package a , t_StockPlace b ");
            commandText.Append(" where a.PkgsStatus in ('0','1')");
            commandText.Append(" and a.PosiID = b.FSPID ");
            commandText.Append(" and b.PlaceBarCode = '" + PlaceBarCode + "'");

            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                dt = DbHelperSQL.Query(commandText.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (dt != null)
            {
                lb_return = true;

                foreach (DataRow dr in dt.Tables[0].Rows)
                {
                    Floor = dr[0].ToString().Trim();
                }
            }

            return lb_return;
        }




        //完成入库单
        /// <summary>
        /// 判断是否可以完成入库
        /// </summary>
        /// <returns></returns>
        public bool IsFinishEnter(string FBillNo, string FEntryID, out string txt)
        {
            txt = "";
            //先判断审核了没有
            if (IsEnterExamine(FBillNo, FEntryID)) { } else { txt = "入库未审核"; return false; }
            //判断明细是否都有库位
            if (IsEnterDetail(FBillNo, FEntryID)) { } else { txt = "入库明细录入不正确"; return false; }
            //判断入库数量是否正确
            if (IsEnterNum(FBillNo, FEntryID)) { } else { txt = "入库单数量不正确"; return false; }

            return true;
        }



        //判断入库单状态
        public bool IsEnterExamine(string FBillNo, string FEntryID)
        {
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            string ls_status = "";
            commandText.Append(" select states from t_SEOutStockEntry ");
            commandText.Append(" where FBillNo='" + FBillNo + "' and FEntryID ='" + FEntryID + "'");
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                ds = DbHelperSQL.Query(commandText.ToString());

            }
            catch (Exception ex)
            {
                throw ex;
            }
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ls_status = dr[0].ToString().Trim();
            }

            if (ls_status == "6") { } else { return false; }

            return true;
        }

        //判断入库单明细是否都有库位
        public bool IsEnterDetail(string FBillNo, string FEntryID)
        {
            DataSet ds = new DataSet();
            StringBuilder commandText = new StringBuilder();
            commandText.Append(" select FBillNo,StockID,PosiID,FLOOR,PkgsIsRegular from t_AbanINStockDetail ");
            commandText.Append(" where FBillNo='" + FBillNo + "' and FEntryID = '" + FEntryID + "'");
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                ds = DbHelperSQL.Query(commandText.ToString());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (ds != null)
            {
                foreach (DataTable dt in ds.Tables)   //遍历所有的datatable
                {

                    foreach (DataRow dr in dt.Rows)
                    {
                        string StockID = dr["StockID"].ToString().Trim(); if (StockID == null || StockID == "" || StockID == "0") { return false; }
                        string PosiID = dr["PosiID"].ToString().Trim(); if (PosiID == null || PosiID == "" || PosiID == "0") { return false; }
                        //string FLOOR = dr["FLOOR"].ToString().Trim(); if (FLOOR == null || FLOOR == "" || FLOOR == "0") { return false; }
                        string PkgsIsRegular = dr["PkgsIsRegular"].ToString().Trim(); if (PkgsIsRegular == null || PkgsIsRegular == "" || PkgsIsRegular == "0") { return false; }
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }

        //判断入库数量主细表是否正确
        public bool IsEnterNum(string fBrNo, string FEntryID)
        {
            bool result = false;
            StringBuilder sql = new StringBuilder();
            DataSet ds = new DataSet();
            sql.Append(" select flag from t_AbanINStockDetail where FBillNo ='" + fBrNo + "' and FEntryID ='" + FEntryID + "' group by flag order by flag");

            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                ds = DbHelperSQL.Query(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (ds != null)
            {
                foreach (DataTable dt in ds.Tables)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        string flag = dr["flag"].ToString().Trim(); if (flag == null || flag == "" || flag == "0") { return false; }
                    }
                }
            }
            else
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 完成报废入库
        /// </summary>
        /// <param name="FBillNo"></param>
        /// <returns></returns>
        public bool FinishAbanINStockEnter(string FBillNo, String FEntryID)
        {
            bool result = false;
            StringBuilder sql = new StringBuilder();
            StringBuilder sql1 = new StringBuilder();
            List<string> commandText = new List<string>();
            DataSet ds = new DataSet();
            DataTable dt1 = new DataTable();
            string FBrNo = DateTime.Now.ToString("yyyyMMddHHmmss").ToString().Substring(2, 12);
            string Ntime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string StickLen = "";
            string ItemSku = "";
            string XSCKDH = "";
            string XSDDH = "";
            int k = 0;

            sql.Append(" select a.PkgsBarCode,a.FSku ItemSku,a.StickLen,a.Stick,a.FQty,a.StockID,a.PosiID,0 PkgsStatus,");
            sql.Append(" a.FinishID InStkMan,XSCKDH,XSDDH,FBillNo AbanINStockBillNo,a.PkgsIsRegular");
            sql.Append(" from t_AbanINStockDetail a ");
            sql.Append(" where FBillNo = '" + FBillNo + "' and FEntryID = '" + FEntryID + "'");
            sql.Append(" order by a.StockID,a.PosiID  ");
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                ds = DbHelperSQL.Query(sql.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (ds != null)
            {
                foreach (DataTable dt in ds.Tables)
                {
                    int num = 0;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string PkgsBarCode = dt.Rows[i]["PkgsBarCode"].ToString().Trim();
                        ItemSku = dt.Rows[i]["ItemSku"].ToString().Trim();
                        StickLen = dt.Rows[i]["StickLen"].ToString().Trim();
                        XSCKDH=dt.Rows[i]["XSCKDH"].ToString().Trim();
                        XSDDH = dt.Rows[i]["XSDDH"].ToString().Trim();
                        string Stick = dt.Rows[i]["Stick"].ToString().Trim();
                        string FQty = dt.Rows[i]["FQty"].ToString().Trim();
                        string StockID = dt.Rows[i]["StockID"].ToString().Trim();
                        string PosiID = dt.Rows[i]["PosiID"].ToString().Trim();
                        string PkgsStatus = dt.Rows[i]["PkgsStatus"].ToString().Trim();
                        string InStkMan = dt.Rows[i]["InStkMan"].ToString().Trim();
                        string dc = dt.Rows[i]["PkgsIsRegular"].ToString().Trim();
                        string FLOOR = "";
                        if (i == 0)
                        {
                            FLOOR = GetMaxFloor(StockID, PosiID);
                            num = 1;
                        }
                        else
                        {
                            string OPosiID = dt.Rows[i - 1]["PosiID"].ToString();
                            if (OPosiID == PosiID)
                            {
                                FLOOR = (int.Parse(GetMaxFloor(StockID, PosiID)) + num).ToString();
                                num++;
                            }
                            else
                            {
                                FLOOR = GetMaxFloor(StockID, PosiID);
                                num = 1;
                            }
                        }

                        k = Judge(PkgsBarCode);
                        if (k > 0)
                        {
                            commandText.Add(" update stk_Package set FBrNo ='" + FBrNo + @"', StockID ='" + StockID + @"' ,PosiID = '" + PosiID + @"',
                        Floor ='" + FLOOR + @"' ,InStkTime = '" + Ntime + @"',InStkMan ='" + InStkMan + @"' ,
                        PkgsStatus ='" + PkgsStatus + @"' ,WorkBillNo ='" + FBillNo + @"' ,AbanINStockBillNo ='" + FBillNo + @"' ,
                         InStkBillNo ='" + FBillNo + @"' ,dc='" + dc + @"'                         
                          where PkgsBarCode ='" + PkgsBarCode + "' and PkgsStatus ='2' ");
                        }
                        else
                        {
                            commandText.Add(@" insert into stk_Package(FBrNo,PkgsBarCode,ItemSku,StickLen,Stick,FQty,StockID,PosiID,Floor,
                         InStkTime,InStkMan,PkgsStatus,WorkBillNo,AbanINStockBillNo,InStkBillNo,dc)values('" + FBrNo + @"','" + PkgsBarCode + @"',
                           '" + ItemSku + @"','" + StickLen + @"','" + Stick + @"','" + FQty + @"','" + StockID + @"','" + PosiID + @"','" + FLOOR + @"',
                             '" + Ntime + @"', '" + InStkMan + @"', '" + PkgsStatus + @"','" + FBillNo + @"','" + FBillNo + @"','" + FBillNo + @"','" + dc + @"') ");
                        }
                    }
                }
            }
           
           
            commandText.Add(@"   update t_SEOutStockEntry set states = '7' where FBillNo= '" + FBillNo + "' and FEntryID ='" + FEntryID + "'");
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                int j = DbHelperSQL.ExecuteSqlTran(commandText);
                if (j > 0)
                {
                    result = true;
                bool  result1 =  UpdateAbanINStockQty(XSCKDH,XSDDH, FBillNo, StickLen, ItemSku);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return result;
        }

        //更新报废入库单数量
       public bool UpdateAbanINStockQty(string  XSCKDH,string XSDDH, string FBillNo,string StickLen,string ItemSku)
        {
            DataTable dt1 = new DataTable();
            DataSet dt2 = new DataSet();
            List<string> commandText = new List<string>();
            bool result = false;
           //获取销售出库单的红冲入库数量
            //dt1 = GetAbanINStockQty(XSCKDH, FBillNo, StickLen, ItemSku);
            //if (dt1 != null)
            //{
            //    foreach (DataRow dr in dt1.Rows)
            //    {
            //        string actual = dr["actual"].ToString();
            //        commandText.Add(@"   update t_SEOutStockEntry set AbanINStockQty ='" + actual + "' where FBillNo='" + XSCKDH + "' and FSku ='" + ItemSku + "' and FEntryIDLenth ='" + StickLen + "' and States = '4'");
            //    }
            //}
           //获取销售订单的红冲入库数量
            dt2 = GetAbanINStockXSDDQty(XSDDH,ItemSku);

            if (dt2 != null)
            {
                foreach (DataRow dr in dt2.Tables[0].Rows)
                {
                    string AbanINStockQty = dr["AbanINStockQty"].ToString();
                    commandText.Add(@"   update t_SEOrderEntry set  AbanINStockQty ='"+AbanINStockQty+@"'   where FInterID in
                    (select FInterID from t_SEOrder where FBillNo='" + XSDDH + "') and FSku ='" + ItemSku + "'");
        
                }
            
            }


            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                int j = DbHelperSQL.ExecuteSqlTran(commandText);
                if (j > 0)
                {
                    result = true;                   
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
         
        }

       //获取销售订单的红冲入库数量
       public DataSet GetAbanINStockXSDDQty(string XSDDH, string ItemSku)
       {
           StringBuilder sql = new StringBuilder();
           DataSet dt = new DataSet();
           sql.Append("select SUM(FQty) AbanINStockQty from t_AbanINStockDetail where XSDDH='" + XSDDH + "' and FSku ='" + ItemSku + "'");

           try
           {
               DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                dt = DbHelperSQL.Query(sql.ToString());             
           }
           catch (Exception ex)
           {
               throw ex;
           }
           return dt;
       
       }

        //判断库存表中是否包含PkgsBarCode条码
        public int Judge(string PkgsBarCode)
        {
            int k = 0;
            StringBuilder sql = new StringBuilder();
            DataSet dt = new DataSet();

            sql.Append("select COUNT(0) num from stk_Package where PkgsBarCode ='" + PkgsBarCode + "'");

            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                dt = DbHelperSQL.Query(sql.ToString());
                foreach (DataRow dr in dt.Tables[0].Rows)
                {
                    k = int.Parse(dr["num"].ToString());

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return k;
        }

        /// <summary>
        /// 获得销售出库单中的报废入库数量
        /// </summary>
        /// <param name="FBillNo"></param>
        /// <param name="StickLen"></param>
        /// <param name="FSku"></param>
        /// <returns></returns>
        public DataTable GetAbanINStockQty(string XSCKDH,string FBillNo, string StickLen, string FSku)
        {
            StringBuilder sql1 = new StringBuilder();
            DataTable dt = new DataTable();
            sql1.Append("   SELECT FBillNo, sum(case States when '4' then AbanINStockQty else 0 end)  AbanINStockQty,");
            sql1.Append("  sum(case States  when '7' then AbanINStockQty else 0 end)  actual,");
            sql1.Append("  FSku,FEntryIDLenth  FROM t_SEOutStockEntry ");
            sql1.Append("  where FBillNo = '" + XSCKDH + "'  and FEntryIDLenth ='" + StickLen + "' and FSku ='" + FSku + "'");
            sql1.Append("  group by FBillNo,FSku,FEntryIDLenth");
            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                dt = DbHelperSQL.QueryTable(sql1.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }


        /// <summary>
        /// 计算层
        /// </summary>
        /// <returns></returns>
        public string GetMaxFloor(string StockID, string PosiID)
        {
            string ls_return = "";
            string floor = "";
            DataSet dt = new DataSet();

            StringBuilder commandText = new StringBuilder();

            commandText.Append(" select MAX(FLOOR) FLOOR ");
            commandText.Append(" from stk_Package ");
            commandText.Append(" where PkgsStatus in (0,1) ");
            commandText.Append(" and StockID = " + StockID);
            commandText.Append(" and PosiID = " + PosiID);

            try
            {
                DbHelperSQL.connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
                dt = DbHelperSQL.Query(commandText.ToString());

            }
            catch (Exception ex)
            {
                throw ex;
            }
            if (dt != null)
            {
                foreach (DataRow dr in dt.Tables[0].Rows)
                {
                    floor = dr[0].ToString().Trim();
                }
            }
            if (floor == "" || floor == null)
            {
                ls_return = "1";
            }
            else
            {
                int maxfloor = 0;
                maxfloor = int.Parse(floor) + 1;
                ls_return = maxfloor.ToString();
            }

            return ls_return;
        }
    }
}
